package com.kevin.Code.LinkNode;

/**
 * @author Vinlee Xiao
 * @Classname IntersectionofTwoLinkedLists
 * @Description Leetcode 160. 相交链表 简单难度
 * @Date 2021/11/7 9:49
 * @Version 1.0
 */
public class IntersectionofTwoLinkedLists {

    /**
     * @param headA
     * @param headB
     * @return
     */
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        //
        if (headA == null || headB == null) {
            return null;
        }

        ListNode moveA = headA;
        ListNode moveB = headB;

        while (moveA != moveB) {
            moveA = moveA == null ? headB : moveA.next;
            moveB = moveB == null ? headA : moveB.next;
        }

        return moveA;
    }
}
